<?php
   
   class MyDB extends SQLite3
   {
      function __construct()
      {  
      $name=$_POST['name'];
      if($name==""){
          echo "姓名未填   ";
      }
      echo "<br>";
      echo "正在查询跟{$name}相关的数据项。。。<br>";
         $this->open('students1.db');
      }
   }
   $db = new MyDB();
   if(!$db){
      echo $db->lastErrorMsg();
   } else {
      echo "查询完毕，以下是查询结果。。。";
   }
   $name=$_POST['name'];
   if(strlen($name)>=1){
  $sql =<<<EOF
      SELECT * from students where 姓名 like '%{$name}%';
EOF;
     }
    else{
    $sql =<<<EOF
SELECT * from students;
EOF;
    }
      
   echo "<table border='5'>
<tr>
<th>序号</th>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>族别</th>
<th>院系</th>
<th>班级</th>
<th>宿舍号</th>
</tr>";


$ret = $db->query($sql);
   while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
      echo "<tr>";
      echo "<td>". $row['序号'] . "</td>\n";
      echo "<td>". $row['学号'] ."</td>\n";
      echo "<td>". $row['姓名'] ."</td>\n";
      echo "<td>". $row['性别'] ."</td>\n";
      echo "<td>". $row['民族'] . "</td>\n";
      echo "<td>". $row['学院'] ."</td>\n";
      echo "<td>". $row['班级'] ."</td>\n";
      echo "<td>". $row['宿舍号'] ."</td>\n";
      echo "</tr>";
   }
   echo "</table>";
   $db->close();
?>